package com.xjy.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.system.domain.ReportContractExecute;
import com.xjy.system.domain.bo.ReportContractExecuteQueryBo;
import com.xjy.system.domain.vo.ReportContractExecuteVo;
import com.xjy.system.mapper.ReportContractExecuteMapper;
import com.xjy.system.service.IReportContractExecuteService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 合同执行报告Service业务层处理
 *
 * @author mlb
 * @date 2022-03-10
 */
@Service
public class ReportContractExecuteServiceImpl extends ServicePlusImpl<ReportContractExecuteMapper, ReportContractExecute> implements IReportContractExecuteService {

    @Override
    public ReportContractExecuteVo queryById(Long projId){
        return getVoById(projId, ReportContractExecuteVo.class);
    }

    @Override
    public TableDataInfo<ReportContractExecuteVo> queryPageList(ReportContractExecuteQueryBo bo) {
        PagePlus<ReportContractExecute, ReportContractExecuteVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ReportContractExecuteVo.class);
		List<ReportContractExecuteVo> reportContractExecuteVoList = result.getRecordsVo();
		if(null == reportContractExecuteVoList || reportContractExecuteVoList.size() == 0 || (reportContractExecuteVoList.size() == 1 && null == reportContractExecuteVoList.get(0))){
			result.setRecordsVo(new ArrayList<>());
			result.setSize(0);
			result.setTotal(0);
		}
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<ReportContractExecuteVo> queryList(ReportContractExecuteQueryBo bo) {
        return listVo(buildQueryWrapper(bo), ReportContractExecuteVo.class);
    }

    private LambdaQueryWrapper<ReportContractExecute> buildQueryWrapper(ReportContractExecuteQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportContractExecute> lqw = Wrappers.lambdaQuery();
        lqw.like(StrUtil.isNotBlank(bo.getProjName()), ReportContractExecute::getProjName, bo.getProjName());
        lqw.between(params.get("beginSignTime") != null && params.get("endSignTime") != null,
            ReportContractExecute::getSignTime ,params.get("beginSignTime"), params.get("endSignTime"));
        lqw.like(StrUtil.isNotBlank(bo.getConstractName()), ReportContractExecute::getConstractName, bo.getConstractName());
        lqw.eq(StrUtil.isNotBlank(bo.getConstractBigType()), ReportContractExecute::getConstractBigType, bo.getConstractBigType());
        lqw.like(StrUtil.isNotBlank(bo.getResultProjectName()), ReportContractExecute::getResultProjectName, bo.getResultProjectName());
        return lqw;
    }


}
